﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using YiSha.Util;
using YiSha.Util.Model;
using YiSha.Entity;
using YiSha.Model;
using YiSha.Admin.Web.Controllers;
using YiSha.Entity.QixingManage;
using YiSha.Business.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Model.Result.QixingManage;
using YiSha.Web.Code;

namespace YiSha.Admin.Web.Areas.QixingManage.Controllers
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2023-03-19 19:47
    /// 描 述：订单管理控制器类
    /// </summary>
    [Area("QixingManage")]
    public class OrderMasterController :  BaseController
    {
        private OrderMasterBLL orderMasterBLL = new OrderMasterBLL();

        #region 视图功能
        [AuthorizeFilter("qixing:ordermaster:view")]
        public ActionResult OrderMasterIndex()
        {
            return View();
        }

        public ActionResult OrderMasterForm()
        {
            return View();
        }

        public ActionResult MasterOrderDetailForm()
        {
            return View();
        }

        public ActionResult ShippingProductForm() 
        {
            return View();
        }

        public ActionResult SelectCar()
        {
            return View();
        }
        #endregion

        #region 获取数据
        [HttpGet]
        public ActionResult GetMasterOrderFormJson(long id)
        {
            TData<OrderDto> obj =orderMasterBLL.GetMasterOrderEntity(id);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:ordermaster:search")]
        public async Task<ActionResult> GetListJson(OrderMasterListParam param)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<OrderMasterEntity>> obj = await orderMasterBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:ordermaster:search")]
        public async Task<ActionResult> GetPageListJson(OrderMasterListParam param, Pagination pagination)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
                param.shopid = operatorInfo.shopid;
            }
            TData<List<OrderMasterEntity>> obj = await orderMasterBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        public async Task<ActionResult> GetFormJson(long id)
        {
            TData<OrderMasterEntity> obj = await orderMasterBLL.GetEntity(id);
            return Json(obj);
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("qixing:ordermaster:add,qixing:ordermaster:edit")]
        public async Task<ActionResult> SaveFormJson(OrderMasterEntity entity)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                entity.tenant_id = operatorInfo.tenant_id;
            }
            TData<string> obj = await orderMasterBLL.SaveForm(entity);
            return Json(obj);
        }

        /// <summary>
        /// 发货
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaveShippingProductForm(OrderMasterEntity entity)
        {
            TData<string> obj = await orderMasterBLL.SaveShippingProductForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("qixing:ordermaster:delete")]
        public async Task<ActionResult> DeleteFormJson(string ids)
        {
            TData obj = await orderMasterBLL.DeleteForm(ids);
            return Json(obj);
        }
        #endregion
    }
}
